package com.liao.service.impl;

import com.liao.dto.StatisticsDTO;
import com.liao.mapper.BookCategoryMapper;
import com.liao.mapper.BookMapper;
import com.liao.mapper.BookPublisherMapper;
import com.liao.mapper.UserMapper;
import com.liao.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class StatisticServiceImpl implements StatisticService {

    @Autowired
    private BookMapper bookMapper;

    @Autowired
    private BookCategoryMapper bookCategoryMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BookPublisherMapper bookPublisherMapper;


    @Override
    public StatisticsDTO getDashboardStatistics() {
        int bookCount = bookMapper.selectCount(null).intValue();
        int userCount = userMapper.selectCount(null).intValue();
        int categoryCount = bookCategoryMapper.selectCount(null).intValue();
        int publisherCount = bookPublisherMapper.selectCount(null).intValue();
        return StatisticsDTO.builder().bookCount(bookCount).userCount(userCount).categoryCount(categoryCount).publisherCount(publisherCount).build();
    }
}
